﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>新闻管理 </title>
    <link href="../static/css/admin.css?v=6" rel="stylesheet" />
    <script src="../static/js/boot.js?v=2"></script>
    <script src="../static/js/admin.js?v=2"></script>

    <script type="text/javascript" charset="utf-8" src="../static/lib/ueditor/ueditor.config.js?2023"></script>
    <script type="text/javascript" charset="utf-8" src="../static/lib/ueditor/ueditor.all.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="../static/lib/ueditor/formdesign/leipi.formdesign.v4.js?2023"></script>
    <script type="text/javascript" charset="utf-8" src="../static/lib/ueditor/lang/zh-cn/zh-cn.js"></script>

    <!--<link href="../static/lib/bootstrap-fileinput/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" />
    <script src="../static/lib/bootstrap-fileinput/js/fileinput.js" type="text/javascript"></script>
    <script src="../static/lib/bootstrap-fileinput/js/fileinput_locale_zh.js" type="text/javascript"></script>-->

    <script>
        var apiUrl = API_PATH + "/News/";
        var keyValue = $.request("keyValue");
        var IsEdit = $.request("IsEdit");
        var selectValue = 0;
        var kty = 1;
        var ue;
        $(function () {
            initControl();
            console.log(keyValue);
            if (!!keyValue) {
                $.ajax({
                    url: apiUrl + "GetNewsInfo?ID=" + keyValue,
                    dataType: "json",
                    async: false,
                    beforeSend: function (jqXHR) {
                        jqXHR.setRequestHeader("Authorization", 'Bearer ' + window.LS.get("lmgcmstoken"));
                    },
                    success: function (ret) {
                        $("#form1").formSerialize(ret.news);

                        //ue.setContent(ret.newsdata.NewsText);
                        $('#myEditor').html(ret.newsdata.NewsText);
                        $("#headPic").attr('src', ret.news.TitlePic);
                        if (ret.news.IsGood == "0") {
                            $('#IsGood').val("否")
                        } else {
                            $('#IsGood').val("是")
                        }
                        if (ret.news.CloseComment == "0") {
                            $('#CloseComment').val("否")
                        } else {
                            $('#CloseComment').val("是")
                        }
                        if (ret.news.IsDokey == "0") {
                            $('#IsDokey').val("否")
                        } else {
                            $('#IsDokey').val("是")
                        }

                    }
                });
            }
            if (IsEdit == "0") {
                //查看
                $("#btn_finish").attr("disabled", "disabled");
            }
        })
        function initControl() {
            //表单设计器
            ue = UE.getEditor('myEditor', {
                //allowDivTransToP: false,//阻止转换div 为p
                toolleipi: false,//是否显示，设计器的 toolbars
                textarea: 'design_content',
                //这里可以选择自己需要的工具按钮名称,此处仅选择如下五个
                toolbars: [[
                    'fullscreen', 'source'
                    , '|', 'undo', 'redo'
                    , '|', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'removeformat'
                    , '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist'
                    , '|', 'fontfamily', 'fontsize'
                    , '|', 'indent'
                    , '|', 'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify'
                    , '|', 'link', 'unlink','simpleupload'
                    , '|', 'inserttable', 'deletetable', 'mergecells', 'splittocells']],
                //关闭字数统计
                wordCount: false,
                //关闭elementPath
                elementPathEnabled: false,
                autoHeightEnabled: false
                //默认的编辑区域高度
                , initialFrameHeight: 390
                , iframeCssUrl: RESOURCES_PATH + "/lib/ueditor/formdesign/bootstrap/css/bootstrap.min.css" //引入自身 css使编辑器兼容你网站css
                //更多其他参数，请参考ueditor.config.js中的配置项
            });
            $("#form1").find('.mainContent').height($(window).height() - 205);
            $("#AddTime").val(new Date().Format('yyyy-MM-dd hh:mm:ss'));

            tabSwitch(0);
            UploadPic();
        }
        function tabSwitch(num) {
            switch (num) {
                case 0:
                    $("#div_jbxx").show();
                    $("div[id=div_main]").children("div[id!=div_jbxx]").hide();
                    break;
                case 1:
                    $("#div_newstext").show();
                    $("div[id=div_main]").children("div[id!=div_newstext]").hide();
                    break;
                case 2:
                    $("#div_titlepic").show();
                    $("div[id=div_main]").children("div[id!=div_titlepic]").hide();
                    break;
                default:
            }
        }
        function submitForm() {
            if (!$('#form1').formValid()) {
                return false;
            }
            var aurl = apiUrl + "SubmitSaveForm?isUpdate=false";
            if (!!keyValue) {
                aurl = apiUrl + "SubmitSaveForm?isUpdate=true";
            }
            var paramform = $("#form1").formSerialize();
            paramform["NewsText"] = ue.getContent();

            if ($('#IsGood').val() == "是") {
                paramform["IsGood"] = 1;
            } else {
                paramform["IsGood"] = 0;
            }
            if ($('#CloseComment').val() == "是") {
                paramform["CloseComment"] = 1;
            } else {
                paramform["CloseComment"] = 0;
            }
            if ($('#IsDokey').val() == "是") {
                paramform["IsDokey"] = 1;
            } else {
                paramform["IsDokey"] = 0;
            }

            $.submitForm({
                url: aurl,
                param: paramform,
                paramType: true,
                success: function () {
                    $.currentWindow().$("#gridList").resetSelection();
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            })
        }


        function UploadPic() {
            let fil = document.querySelector('#file1')
            let headPic = document.querySelector('#headPic')
            headPic.addEventListener('click', function () {
                fil.click()
            });
            //头像上传
            fil.addEventListener('change', function (e) {
                var formData = new FormData();
                formData.append('files', $("#file1")[0].files[0]);  /*获取上传的图片对象*/
                $.ajax({
                    url: API_PATH + '/File/Upload',
                    type: 'POST',
                    data: formData,
                    contentType: false,
                    processData: false,
                    success: function (args) {
                        var json2 = eval("(" + args + ")");
                        console.log(json2);
                        $("#headPic").attr('src', "/upfile/"+json2[0]);
                        $("#TitlePic").val(json2[0]);
                    }
                })
            })
        }
    </script>
</head>
<body style="margin:0px;padding:0px;overflow:hidden;">
    <form id="form1">
        <div style="margin-top: 10px; margin-left: 10px; margin-right: 10px;">
            <div style="padding-top: 2px;">
                <input type="hidden" id="ID" name="ID" value="" />
                <input type="hidden" id="KeyBoard" name="KeyBoard" value="" />
                <input type="hidden" id="AddTime" name="AddTime" value="" />
                <input type="hidden" id="TitlePic" name="TitlePic" />
                <ul id="myTab" class="nav nav-tabs">
                    <li class="active">
                        <a data-toggle="tab" onclick="tabSwitch(0)">基本信息</a>
                    </li>
                    <li>
                        <a data-toggle="tab" onclick="tabSwitch(1)">新闻内容</a>
                    </li>
                    <li>
                        <a data-toggle="tab" onclick="tabSwitch(2)">上传封面</a>
                    </li>
                </ul>
                <div id="div_main" style="">
                    <div id="div_jbxx" style="display:none">
                        <table class="form">
                            <tr>
                                <th class="formTitle">分类<span style="color:#ff0000">*</span></th>
                                <td class="formValue">
                                    <div class="input-group">
                                        <input id="Category" name="Category" title="双击清空" value="新闻资讯" ondblclick="$('#Category').val('');" readonly="readonly" type="text" class="form-control required" placeholder="请选择" />
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-info dropdown-toggle" data-bs-toggle="dropdown" data-toggle="dropdown">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu pull-right" style="max-height:200px;overflow:auto">
                                                <li><a class="dropdown-item" onclick="selectOption('Category', this);">新闻资讯</a></li>
                                                <li><a class="dropdown-item" onclick="selectOption('Category',this);">常见问题</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">标题<span style="color:#ff0000">*</span></th>
                                <td class="formValue" colspan="5">
                                    <input id="Title" name="Title" type="text" class="form-control required" autocomplete="off" maxlength="200" />
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">副标题<span style="color:#ff0000"></span></th>
                                <td class="formValue" colspan="5">
                                    <input id="FTitle" name="FTitle" type="text" class="form-control" autocomplete="off" maxlength="200" />
                                </td>
                            </tr>

                            <tr>
                                <th class="formTitle">简介<span style="color:#ff0000">*</span></th>
                                <td class="formValue" colspan="5">
                                    <textarea id="SmallText" name="SmallText" class="form-control" rows="3"></textarea>
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">外链<span style="color:#ff0000"></span></th>
                                <td class="formValue" colspan="5">
                                    <input id="Url" name="Url" type="text" class="form-control" autocomplete="off" maxlength="200" placeholder="http://" />
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">来源<span style="color:#ff0000"></span></th>
                                <td class="formValue">
                                    <input id="Befrom" name="Befrom" type="text" class="form-control " autocomplete="off" maxlength="200" />
                                </td>
                                <th class="formTitle">作者<span style="color:#ff0000"></span></th>
                                <td class="formValue">
                                    <div class="input-group">
                                        <input id="Author" name="Author" title="双击清空" value="本站" ondblclick="$('#Author').val('');" type="text" class="form-control " placeholder="请选择" />
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-info dropdown-toggle" data-bs-toggle="dropdown" data-toggle="dropdown">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu pull-right" style="max-height:200px;overflow:auto">
                                                <li><a class="dropdown-item" onclick="selectOption('Author', this);">本站</a></li>
                                                <li><a class="dropdown-item" onclick="selectOption('Author',this);">网文</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </td>

                            </tr>
                            <tr>
                                <th class="formTitle">推荐<span style="color:#ff0000"></span></th>
                                <td class="formValue">
                                    <div class="input-group">
                                        <input id="IsGood" name="IsGood" title="双击清空" value="否" ondblclick="$('#IsGood').val('');" readonly="readonly" type="text" class="form-control" placeholder="请选择" />
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-info dropdown-toggle" data-bs-toggle="dropdown" data-toggle="dropdown">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu pull-right" style="max-height:200px;overflow:auto">
                                                <li><a class="dropdown-item" onclick="selectOption('IsGood', this);">是</a></li>
                                                <li><a class="dropdown-item" onclick="selectOption('IsGood',this);">否</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                                <th class="formTitle">关闭评论<span style="color:#ff0000"></span></th>
                                <td class="formValue">
                                    <div class="input-group">
                                        <input id="CloseComment" name="CloseComment" title="双击清空" value="否" ondblclick="$('#CloseComment').val('');" readonly="readonly" type="text" class="form-control" placeholder="请选择" />
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-info dropdown-toggle" data-bs-toggle="dropdown" data-toggle="dropdown">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu pull-right" style="max-height:200px;overflow:auto">
                                                <li><a class="dropdown-item" onclick="selectOption('CloseComment', this);">是</a></li>
                                                <li><a class="dropdown-item" onclick="selectOption('CloseComment',this);">否</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th class="formTitle">替换内容关键字<span style="color:#ff0000"></span></th>
                                <td class="formValue">
                                    <div class="input-group">
                                        <input id="IsDokey" name="IsDokey" title="双击清空" value="否" ondblclick="$('#IsDokey').val('');" readonly="readonly" type="text" class="form-control" placeholder="请选择" />
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-info dropdown-toggle" data-bs-toggle="dropdown" data-toggle="dropdown">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu pull-right" style="max-height:200px;overflow:auto">
                                                <li><a class="dropdown-item" onclick="selectOption('IsDokey', this);">是</a></li>
                                                <li><a class="dropdown-item" onclick="selectOption('IsDokey',this);">否</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div id="div_newstext" style="display:none;">
                        <table class="form">
                            <tr style="">
                                <td>
                                    <div class="mainContent" style="margin: 1px; margin-bottom: 0px; padding: 0;">
                                        <script id="myEditor" type="text/plain" style="width: 100%;"></script>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div id="div_titlepic" style="display:none;">
                        <table class="form">
                            <tr>
                                <th class="formTitle">封面<span style="color:#ff0000"></span></th>
                                <td class="formValue">

                                    <div class="form-group">
                                        <div><img id="headPic" src=" ../static/img/jiahao.png" onerror="this.src=' ../static/img/jiahao.png'" /></div>
                                        <input type="file" id="file1" name="file1" />
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>



            </div>
        </div>
    </form>
</body>
</html>